package com.hndfsj.common.service.impl;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import com.hndfsj.common.dao.IValuesDao;
import com.hndfsj.common.domain.Values;
import com.hndfsj.common.service.IValuesService;
import com.hndfsj.common.web.ResourceController;
import com.hndfsj.framework.dao.base.IBaseDao;
import com.hndfsj.framework.exceptions.ValidateParamException;
import com.hndfsj.framework.service.base.BaseServiceImpl;
import com.hndfsj.framework.utils.CryptUtil;
import com.hndfsj.framework.utils.UUIDGenerator;

/**
 * TODO 
 * @copyright {@link www.hndfsj.com}
 * @author ZhengXingJian<Auto generate>
 * @version  2016-11-09 11:44:23
 * @see com.hndfsj.common.service.impl.Values
 */
@Service("valuesService")
public class ValuesServiceImpl extends BaseServiceImpl<Values,  java.lang.String > implements IValuesService {

	static Logger log=LoggerFactory.getLogger(ValuesServiceImpl.class);

	@Resource
	private IValuesDao valuesDao;
	
	@Override
	protected IBaseDao<Values , java.lang.String> getBaseDao() {
		return this.valuesDao;
	}
	public void validateEntity(Values values)throws ValidateParamException {
		//TODO write validate code throw new ValidateParamException
	}
	public  String imgSrcToMD5(String originUrl) {
		String key = CryptUtil.encoderByMd5For32Bit(originUrl);
		try{
//			log.error(key);
			valuesDao.save(new Values(key,originUrl));
			return ResourceController.LOGINDOWNLOAD+key;
		}catch(DuplicateKeyException e){
			return ResourceController.LOGINDOWNLOAD+key;
		}catch(Exception e){
		}
		return ResourceController.LOGINDOWNLOAD+UUIDGenerator.UUIDValue();
	}
	
}
